/*
 * Copyright (c) 2009. Silenus Consultoria, S.L.
 */
package es.silenus.detecta.model;

import java.io.Serializable;

import java.util.Set;


/**
 * User defined group of councils.
 *
 * @author <a href="mailto:malonso@silenus-consultoria.es">Mariano Alonso</a>
 *
 * @since 08-may-2009 11:36:02
 */
public class CouncilGroup implements Serializable {
	/**
	 * Generated identifier.
	 */
	private long id;

	/**
	 * The group name must be unique per organization.
	 */
	private String name;

	/**
	 * The organization.
	 */
	private Organization organization;

	/**
	 * The councils.
	 */
	private Set<Council> councils;

	/**
	 * Retrieves the id.
	 *
	 * @return the id.
	 */
	public long getId() {
		return id;
	}

	/**
	 * Sets the id.
	 *
	 * @param id the id.
	 */
	public void setId(long id) {
		this.id = id;
	}

	/**
	 * Retrieves the name.
	 *
	 * @return the name.
	 */
	public String getName() {
		return name;
	}

	/**
	 * Sets the name.
	 *
	 * @param name the name.
	 */
	public void setName(final String name) {
		this.name = name;
	}

	/**
	 * Retrieves the organization.
	 *
	 * @return the organization.
	 */
	public Organization getOrganization() {
		return organization;
	}

	/**
	 * Sets the organization.
	 *
	 * @param organization the organization.
	 */
	public void setOrganization(final Organization organization) {
		this.organization = organization;
	}

	/**
	 * Retrieves the councils.
	 *
	 * @return the councils.
	 */
	public Set<Council> getCouncils() {
		return councils;
	}

	/**
	 * Sets the councils.
	 *
	 * @param councils the councils.
	 */
	public void setCouncils(final Set<Council> councils) {
		this.councils = councils;
	}

	/**
	 * Adds a council.
	 *
	 * @param council a council.
	 */
	public void add(final Council council) {
		getCouncils().add(council);
	}

	/**
	 * Removes a council.
	 *
	 * @param council a council.
	 */
	public void remove(final Council council) {
		getCouncils().remove(council);
	}

	/**
	 * Checks if objects are equal.
	 *
	 * @param o other object.
	 *
	 * @return true if equal, false otherwise.
	 */
	@Override
	public boolean equals(Object o) {
		if(this == o) {
			return true;
		}

		if(!(o instanceof CouncilGroup)) {
			return false;
		}

		CouncilGroup that = (CouncilGroup)o;

		if(getId() != that.getId()) {
			return false;
		}

		return true;
	}

	/**
	 * Calculates the hash of this instance.
	 *
	 * @return the hash code.
	 */
	@Override
	public int hashCode() {
		return (int)getId();
	}

	/**
	 * Stringifies this instance.
	 *
	 * @return the string representation.
	 */
	@Override
	public String toString() {
		final StringBuilder sb = new StringBuilder();

		sb.append("CouncilGroup");
		sb.append("{id=").append(getId());
		sb.append(", name='").append(getName()).append('\'');
		sb.append('}');

		return sb.toString();
	}
}
